package cn.jr.service.impl;

import cn.jr.dao.IAccountDao;
import cn.jr.dao.IUserDao;
import cn.jr.dao.impl.AccountDaoImpl;
import cn.jr.dao.impl.UserDaoImpl;
import cn.jr.pojo.ShopRun;
import cn.jr.service.IShopService;

//用户表
@SuppressWarnings("all")
public class ShopServiceImpl implements IShopService {

    IUserDao iud = new UserDaoImpl();//用户注册，通过用户名查询
    IAccountDao iad = new AccountDaoImpl();//账户查询

    @Override  // 注册
    public boolean Register(String username, String password) {
        ShopRun sr = new ShopRun();
        sr.setUserName(username);
        sr.setPassword(password);
        return iud.insertUser(sr) > 0 ? true : false;
    }

    @Override  // 登录
    public boolean Login(String username, String password) {
        ShopRun sr = iud.selectUserByUserName(username);
        if (password.equals(sr.getPassword())) {
            return true;
        } else {
            return false;
        }
    }

    @Override // 通过 主键(userId) 查询 用户表-用户名
    public String getShopRunUNameById(int userId) {
        return iud.selectUserByUserId(userId).getUserName();
    }

    @Override // 根据 用户名 查询 用户表主键
    public int getShopRunIdByName(String username) {
        return iud.selectUserByUserName(username).getUserId();
    }

}
